package com.shensi.appCollect.controller;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.internal.util.AlipayEncrypt;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.request.AlipayUserInfoShareRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.alipay.api.response.AlipayUserInfoShareResponse;
import com.google.gson.Gson;
import com.shensi.api.admin.client.station.ThirdPartyWeChatClient;
import com.shensi.appCollect.pojo.AppUserInfo;
import com.shensi.appCollect.constantEnum.RedisKey;
import com.shensi.api.pay.param.request.AppUserInfoRequest;
import com.shensi.appCollect.pojo.Enterprise;
import com.shensi.appCollect.pojo.Station;
import com.shensi.appCollect.pojo.vo.UserInfoVo;
import com.shensi.appCollect.service.AppUserInfoService;
import com.shensi.appCollect.service.EnterpriseService;
import com.shensi.appCollect.service.GzhNewsTemplateService;
import com.shensi.appCollect.service.RegistrationReleaseService;
import com.shensi.appCollect.utils.IdempotentUtil;
import com.shensi.appCollect.utils.JsonUtils;
import com.shensi.appCollect.utils.ResultData;
import com.shensi.appCollect.utils.exception.EndingException;
import com.shensi.appCollect.utils.redis.RedisCacheUtil;
import com.shensi.appCollect.utils.weixinapp.AesDecryptUtil;
import com.shensi.appCollect.utils.weixinapp.HttpRequestUtil;
import com.shensi.appCollect.utils.weixinapp.WeiXinUserUtil;
import com.shensi.appCollect.utils.CodeMsg;
import com.shensi.common.core.constant.RedisKeyPrefixConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;

@Controller
//@QuJiaRequest()
@CrossOrigin
@Api(tags = "app用户登录")
public class AppUserInfoController {
    private static Logger logger = (Logger) LoggerFactory.getLogger(AppUserInfoController.class);
    @Autowired
    private AppUserInfoService appUserInfoService;
    @Resource
    private RedisCacheUtil redisCacheUtil;
    @Resource
    private RegistrationReleaseService registrationReleaseService;
    @Resource
    private EnterpriseService enterpriseService;


    @Value("${domain.adminName}")
    private String adminName;

    @Resource
    private GzhNewsTemplateService gzhNewsTemplateService;
    @Autowired
    private IdempotentUtil idempotentUtil;

    @Value("${wechat.thirdParty.appid}")
    private String componentAppid;


//    String appId = "wxe1135cd390b38a54";        //微信小程序appID
//    String appSecret = "0532c7d9ae876c4ad636df0b1e3b9ddb";      //微信小程序密钥

//    //支付宝小程序：公钥、私钥、解密钥
//    String PRIVATE_KEY ="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCBVAR3NE/UNvnpXNhmx8xX6se8euxQefbbkWLSykgA9dkP7eaNDyllMtuxjNLaQ1VB26sh2us0VrzSsNA7nmX5aPXu7ckHXH6wBzChCeCdDCHVpoHVq5doehgwMQrvh6aUEcPId+szepvoMmKaSEbFmFapZrTxrPOthI6ENR3RRgs+29vYgru+qJtg3V+tsOr1gkhocU16dX9s7zYfSQQNOmFa01aAhtwI9pDKZVYtELrqOg1dP5WY+jMyXReaDLfAP40H3X7+sVuzTCLu4oVE9CMU2rR+hxwjs6rVWbgE4z13IbM3N8FoPjwJJK0+cXYuORE3yHd4eZj3pEFKvCajAgMBAAECggEADHnAXIdtU/lhrkNIlNGdQrXhQqtQ9IpvZ8rkj5T30S/mGoVGgkD+K0b2rm/5PxjTtqCsJ33oxom/eUuZKsci6yZW4w+JHu6rQevPoxlC06OB+Awx5hzBZFCy2KNCfMzHIu17x3DZ/YNMWt/RZzSlrxX89iZ0OgQHFav9238MO02z9ejRPQEWO4tNb7YyHmi1h56fH2Y+cvLh32QWc+t16tkr5HVY6I2ktMIHYpGU4lyfYEjZ01P7QruAVol2lDNiIYVFXfyDvtwqQNWol6iCswSrDFj0LFsdTWEA1OLZUdD/mfLuBJ9nUAHoCyIh3uR+Aag87DRURcFN92hG0cex4QKBgQDwzmdUC1upAKmRTVEcKUUyDxHZxDhfjRoyhZGf6s/paPvWAVo60VGDC2lQeYqQ8sMnWbpAYWq/yFT2bGK9iPD9UoZWKwLSJuR5RAhiet5WpCfvRmEqEVHJtCaZeV0Q4Al2dPZqu/7opFsrrlY5MvdKJZuLCtL/UBdmkz4BJyFwGQKBgQCJfPoIF5EI/4iYvAQM6FNEQ/kbtb3BF9In9m5GwaMP25ho8evkdI0q5H88FI+i+PdqtdM2gKhuNCXNK/LbF8AzEAu0Qr2clwOq6wQzPU4wl0RNrmdg6H/YC1uTgoy4cr9RdTrqOwXT2UyWghP7AjrifcstZVsrdamOxQHRQ/p0GwKBgQC/uHWH8msNyRs4NkiHlUwkKN9bc+A2Iw9iffmNStQxz4YBwp3mClVNcj5s9feeo8lAgS3KqETnYEZU08JhiK/l4FhYLnJWguSQr9vFHHH8pUGuPWiKp7NoVegNdRTlpJmkGEdAf2DaNFDqHClF7Q/5lquaLgoDf+7BmiVZoZ/7sQKBgF9aw1qLZba063rqo3CETQPClOnIAYQDTmkS++as87fS2ICokK9QunuuICR+KiSgwZBL7OIXFznfhvwmZ/fWICIKFeP+id0py4xmFPKoqSsALool1GMcvVYMgoXq/EgMpW4MfUDokKEeS4TzUII9SLO/BQRGEJYys9dmAV2u5OxTAoGAb5qCQVtmmhO+A0GJG4KZ4xd3i54ZiykrRyCLralBudpI6Vr5+N6yD4R5IdqN2iJKcokt1TxtcJzrunKhUHtOXEiLK/k872iWGQhPeMV+sqWcQXQpKLtRhn4dROOP2qgeOHtdkeLoPlIcfd6TjIsGJJCksXE2hNKr6aljS/zhoKo=";
//    String PUBLIC_KEY ="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsXdLLSfp79oe89Q+i1KHx7DfNQjAPWlDaBVtHnwo+jiCkVcNzkeRtz5mZsM3lBURFG6T3eY3qUu0b3FUCSUWd1Q06J4bFI1y4ID3JBCyRi0Up5pcqZzwZqa22QxK3m5/2tabd56FL9C/PPSuQj8gPgT8eUbPUZFeLcnYCLSM0VKU/ZxlXRx9G0MEOZizMxiGdKVwNCE1BxJKTybFz2X0AyakpOWlAZZNQm3JIGfJVHEsc2lgBoeEt8T8d1AJiTdlzAayRGJWpX0nymRZ+RhwQQmuKlPGPvLJDNTV87YvvMttmzlXN32lobK6203PlOoDiLmenj0lxniZfC9tPcRhgwIDAQAB";
//    String ALI_APP_ID = "2021002140684377";
//    String ENCRYPT_KEY ="K5F2BgcYsRYo8YpRnNSTsg==";


    //支付宝小程序：公钥、私钥、解密钥
//    String PRIVATE_KEY ="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCKDRqcbTxFHTxYZc6Vk46JNKrftsPYO/Ex/mQfrwXK9QfLoI9M81hHgEIQ4SKzUelR9HBVbP9B1VDsGaGOxXl/WUoQ2QSGWrJgu7KftKx8d/1MiXlbbDj/T74ugFzbSG+HlmE65Sdlxa9rn8bXzBaN48FdSDXKFU5L5TGNbBfip1TFhgKE24UcyrIM8YDvPNp/3UIHQx1qa1diJ3nvEMajPlzteyLSUb8uGJzNZwAgp+0wz8tJ8pUIdidl4WmjJQIe5FCGFk63y3hlzTyYWt1CYkqVTohHAif4ILwcpHzB1JSUANs8GLhDpgTQMG94qH4FYlbxXDzGAFerdz2G9eqvAgMBAAECggEAKWEcJN8pPZ4xxF1fur3r73x163Cg62OsPEwAPu77UYZ4u7R4v5wBTg1HwD97YzyeLw6RzUlKibUi+GIGZwESFfXxmXMzRAJTjWM1e2Fwgi6FIjfixGCABScl3lJjgucHZyDQLBMb6AmFN0FBHNXzvLwT7Z4DYXtZaK5eWAGadzk1pK+By+Sb1METGjIWaLTv8oay8Vqz6U8+ZmCLgFl//mKMXvcZbiEjr/xrLmpFtkNrSzqX1EBcUACyiUX6fr9G1i1Nf4PHLtYlpPM2nnLDARK7oDJexWoxZPr1v2C8hLDG1rgNk0yBNeG+iOZ7RUPe+JpR4uoZuTEfB6yn3PBHAQKBgQDn1C+G3JSr98hCKgmLRTkt65YZ5uLPK49Om/VDSyfJGPUh4h/KpCxIeR2Ub0CJzUTQwS5T+hJsabF7i2ICSr/bUWfI7S1jZISaoiF+J4H9V8ug+faelkgVKMq6WT3GRSQ2ZcXJgSvspu38Tv5XKVjDe7erFMf3VDBmnk+vUElWjwKBgQCYcd7D3Lz5PNH1wp+ZJyE43MDbL14Zi0o8hBybpwZVez13SNKOReIXPwOKVnfvuX2tDnCVF5M16HbCWNlTybKyfIewdHSw6HMQfxyN41qndso1OB44gq90dMkEft9xPh5dJQS/iHAmpgLiJ/3cUF18wpLRA0IcAxuThgsML5U54QKBgQDlRXXTXGc0Q5MrzEMwFz/baDhEWZFJ7fyGc7r12Gf6e9JCtk1WrVKWQiG84OHk5rr98W+N4a1CxqyeUFSXi7F+h12q2tWejJSQEXQqPYxTLvbVtx/t6xZSxsrnzMZJRavwmGopRLRaESUf+EeVj/CXM82LRrwUoJBVjI+mBDLjhQKBgCpxsetonzjpxS+e857JtUdGt2+PfayxCodU5T41P983BAMdRHqWXH/KbKrsrlIRnDs9xPzN5o/g3If6AvCAPP/TCliH5CGJZtgV/BZJUelEesJckJV9VWqgRYO56251NDEM6IiHbWplWHItXlIkEhN1fTkypgp0lw35CURoTy0hAoGBALVc4NlhgH29DO7BYAyc8jBgypO6kZs0aEBM3uRO/eaIhBQeK4uc2pXgKmajP78HpAnRR+Zj931OncTWlYZlaDmFqiFnYNtBA3FHKzfi8b2XemE4G8fUuR43UuTORDYqau2Ev1kGWZo1Crt4yMgkL7D5zYLKyzVqgl6rWelcirvO";
//    String PUBLIC_KEY ="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsXdLLSfp79oe89Q+i1KHx7DfNQjAPWlDaBVtHnwo+jiCkVcNzkeRtz5mZsM3lBURFG6T3eY3qUu0b3FUCSUWd1Q06J4bFI1y4ID3JBCyRi0Up5pcqZzwZqa22QxK3m5/2tabd56FL9C/PPSuQj8gPgT8eUbPUZFeLcnYCLSM0VKU/ZxlXRx9G0MEOZizMxiGdKVwNCE1BxJKTybFz2X0AyakpOWlAZZNQm3JIGfJVHEsc2lgBoeEt8T8d1AJiTdlzAayRGJWpX0nymRZ+RhwQQmuKlPGPvLJDNTV87YvvMttmzlXN32lobK6203PlOoDiLmenj0lxniZfC9tPcRhgwIDAQAB";
//    String ALI_APP_ID = "2021002194660904";
//    String ENCRYPT_KEY ="QMy9nb3g5i2PJXoml2MVFA==";

//    String PRIVATE_KEY ="MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC+l+rtExlWOA24oKD2RvB4x0pEGHEKYXpAn39qRwmvj5yZkoyk1cFlhd6cjt5/5R8i311EvqBlvFWCu7y4h6pNbPQskOs/2MAoubC35FAuAYGsWJrsAtSqVD9eiJn+P7NLwcA8xzgsvve/O5ujqVOEFdsgI+coq5SNK3TeqHRI5Ho57WMRZ7r30cNzeHf7ph5Arjmgh9BL5m5fRSSVaab4z2amMAgXZAtSnzrrhK0M1W6hxDUgsd2x2j+xFbQAf7Hbs/oOYvDEg2BVzmEiOQSkKFfF+H+fTOfL5hipHvFWSeyNQp35eVz8nfVSDC/tFC37QHZZO/oCg63amqKK6r9TAgMBAAECggEAZ/tkDUGtQg/E1KS2DIb5bTt1Nh+LlJlH5HfgQPBOxXx5eIOuvcNtBuF5aTq9A1PSn+jy7q19vuN4V6HrPVWuwR0fPi02W5f6hn2Af2NNpzvlLk0NAJQuyFq8U+v87+x6+mrTYZVi/W6Wpbt0l16rFNYDvc44sESkADzkPxHyl000PRWXFB3ZemQmc0WxHcw5W7Oh7vbf/LfXglit53zcCWxk4XijmJUOqIhd7QNRdfTt1sMnrcB8tIL/WxmgU+Rf39/WocO4xxnJFfMpoSsZEDabId0yk53aIxV+qhSuGEZpfKoMZ7BBH9Q+txmDOYKvcYnNvSLDVsen8V8U5xWD8QKBgQD+dbnqAVVJhns3kxY44rqMtBJde9ziDYgBi1ZhwSs1FVUQzeRrqJWye8y2xr/KL1+J+2S5RQu9rSDGHv6hK6KlO5FkQL5n+eiAVUzR1bpDKYtPV3f9vWrlTubGUxplDsyS/DZ5Ozt9shCbslmV1qc/4uiQAY6LSGjRkHnbljiACQKBgQC/vzu9yPYHVQuIriC7LlU0JH2TkRyqPg4XEOPiKp800f9kPoqRKWMBSNBdbXuPFCUCi1+PNjK9sxcVY7dLGNHTCYQBZaLpjtLOa1fp+6JGKbApWzuE57cNbdBgWdEyRB7y+QTN3+yLg2uLawOR99qIftICQlZqZgbodDTLSyQjewKBgDjlngKC9c0Q8vBERU3G9KuNgCXDEmrBV83wmAoXpU+jS3gMcazY71APeoDMBApzeUtjGOyMUcnBsnhaadkj5qRHo4TlLS4WpTQ83oZ04ccuvOWqyzvDZOmNMPDbmCVMn9Wl65BD/FNow2ntATcN3ivc0t+QWY0vTbC+O2EsP8nxAoGAIn92cSPJ1/HeHF4vt12TqMjz6uvNu3dks5OvXE6MzEUH7PIvngRTMrT2AAkllM1sBzQqIir/IBArlAaXwKQbhBuPK20szVaL6OV5MLi8LmFrt1UZtUS3M2xRdDRUpfWJl+9jhOLHvSYM4E2Fm+p639npUMy8nXHzxji6EuVXACcCgYBSoHt6FMYcwOAQTtcyatR1MkBWY4Vc1BnewrbD2KOfUvkgWgA0MWMKdy3R5KxshF+htWh+S7Ec52sHMDt1FLz8/B5SoRGd75T4VbsJ/3uxvXUgnZ8wSIg3J56H25vuPwYkGnaWbETmFZZgh1FxByndp/R0NqXPWc3ZPPbqFoi0wA==";
//    String PUBLIC_KEY ="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAykS56Y+Ku5XOd8h8DkUMWahm+RdVZ/vhYUbM1IuuwWz8S9/oI6QmOmemisPtl8/NVejNQ3JovLPCnAjtUPPt207Tdt+T5gmUaaeXWx62m7vWeo7mv5gzSaJn5WrbSTPIBRDbeHbOpvk5BjOqgbVuyA0qQ218SONZBkWt8K1elyeOQg0giw5W6dfNn1iGa2KtlOIqgqQ4pAuTyVl7LdgNAtMAGyrgxlPBNdoBNXQLnOthHnXYf+QpvTjE5Hd3ZgIu5rx9Ny45SVuP3MgUGTLKzXdBkOYHUcxTI26y3aXMP2dB8kVfH+yeOVvipX7HxiAl7mgeIKmtYReSfBcYM4LzyQIDAQAB";
//    String ALI_APP_ID = "2021003191639432";
//    String ENCRYPT_KEY ="sangbk5mWIqmRBZkp7iuLxDt5jg==";

    @Value("${ali.privateKey}")
    private String PRIVATE_KEY;
    @Value("${ali.publicKey}")
    private String PUBLIC_KEY;
    @Value("${ali.appId}")
    private String ALI_APP_ID;
    @Value("${ali.encryptKey}")
    private String ENCRYPT_KEY;


    //获取支付宝用户信息
    @ResponseBody
    @RequestMapping(value = "/getAliUserInfo")
    public String getAliUserInfo(@RequestParam String authCode) {
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        logger.info("获取用户信息所需code：" + authCode);
        if (StringUtils.isNotBlank(authCode)) {
            try {
                AlipayClient alipayClient = new DefaultAlipayClient(
                        "https://openapi.alipay.com/gateway.do",
                        ALI_APP_ID,
                        PRIVATE_KEY,
                        "json",
                        "UTF-8",
                        PUBLIC_KEY,
                        "RSA2");
                AlipaySystemOauthTokenRequest alipaySystemOauthTokenRequest = new AlipaySystemOauthTokenRequest();
                alipaySystemOauthTokenRequest.setGrantType("authorization_code");
                alipaySystemOauthTokenRequest.setCode(authCode);
                AlipaySystemOauthTokenResponse alipaySystemOauthTokenResponse = alipayClient.execute(alipaySystemOauthTokenRequest);
                if (alipaySystemOauthTokenResponse.isSuccess()) {
                    logger.info("支付宝小程序获取access_token：" + alipaySystemOauthTokenResponse.getAccessToken());
                    //获取用户信息
                    AlipayUserInfoShareRequest alipayUserInfoShareRequest = new AlipayUserInfoShareRequest();
                    AlipayUserInfoShareResponse alipayUserInfoShareResponse = alipayClient.execute(alipayUserInfoShareRequest, alipaySystemOauthTokenResponse.getAccessToken());
                    resultData = ResultData.success(alipayUserInfoShareResponse);
                } else {
                    resultData = ResultData.success(alipaySystemOauthTokenResponse);
                }
            } catch (AlipayApiException e) {
                e.printStackTrace();
                resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
            }
        } else {
            resultData = ResultData.error(CodeMsg.PARAMS_NUll);
        }
        return gson.toJson(resultData);
    }

    //获取支付宝用户信息
    @ResponseBody
    @RequestMapping(value = "/getAliUserId")
    public String getAliUserId(@RequestParam String authCode) {
        try {
            if (StringUtils.isBlank(authCode)) {
                throw new EndingException("请传入authCode");
            }
            AlipayClient alipayClient = new DefaultAlipayClient(
                    "https://openapi.alipay.com/gateway.do",
                    ALI_APP_ID,
                    PRIVATE_KEY,
                    "json",
                    "UTF-8",
                    PUBLIC_KEY,
                    "RSA2");
            AlipaySystemOauthTokenRequest alipaySystemOauthTokenRequest = new AlipaySystemOauthTokenRequest();
            alipaySystemOauthTokenRequest.setGrantType("authorization_code");
            alipaySystemOauthTokenRequest.setCode(authCode);
            AlipaySystemOauthTokenResponse alipaySystemOauthTokenResponse = alipayClient.execute(alipaySystemOauthTokenRequest);

            if (!alipaySystemOauthTokenResponse.isSuccess()) {
                throw new EndingException("阿里请求不成功");
            }

            String accessToken = alipaySystemOauthTokenResponse.getAccessToken();
            String userId = alipaySystemOauthTokenResponse.getUserId();
            Map<String, String> resultMap = new HashMap<>();
            resultMap.put("userId", userId);
            return ResultData.successJson(resultMap);
        } catch (EndingException e) {
            return ResultData.errorJsonWithCode(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("/getAliUserId-", e);
            return ResultData.errorJson(e.getMessage());
        }
    }

    //支付宝小程序用户手机号解密 encryptedData
    @ResponseBody
    @RequestMapping(value = "/alipayEncryptUserPhone", method = RequestMethod.POST, consumes = "application/json")
    public String alipayEncryptUserPhone(@RequestBody JSONObject jsonObject) {
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        logger.info("前端解密手机号传递参数信息：" + jsonObject.toString());
        if (StringUtils.isNotBlank(jsonObject.get("response").toString())) {
            try {
                //解密用户手机号数据
                String encryptedData = jsonObject.get("response").toString();
                logger.info("支付宝获取手机号要解密数据: " + encryptedData);
                String aes = AlipayEncrypt.decryptContent(encryptedData, "AES", ENCRYPT_KEY, "UTF-8");
                logger.info("支付宝获取手机号解密后的数据：" + aes);
                resultData = ResultData.success(aes);
            } catch (AlipayApiException e) {
                e.printStackTrace();
                resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
            }
        } else {
            resultData = ResultData.error(CodeMsg.PARAMS_NUll);
        }
        return gson.toJson(resultData);
    }


//    //支付宝小程序用户手机号解密 encryptedData
//    @ResponseBody
//    @RequestMapping(value = "/yunhuaAddUser", method = RequestMethod.POST, consumes = "application/json")
//    public String yunhuaAddUser(@RequestBody String  moblie){
//
//        appUserInfoService.addAppUserInfo(AppUserInfo.builder().mobilePhone(moblie).build());
//        return "111";
//    }

    /*
     * 微信小程序根据code获取用户openId和sessionKey
     * @param code
     * @param stationId
     * @return
     */
    @ResponseBody
    @GetMapping(value = "/getSessionKeyAndOpenID")
    @ApiOperation(value = "微信小程序根据code获取用户openId和sessionKey", httpMethod = "GET", notes = "微信小程序根据code获取用户openId和sessionKey")
    public String getSessionKeyAndOpenID(@ApiParam(value = "code码", required = true) @RequestParam String code,
                                         @ApiParam(value = "油企ID") Integer enterpriseId,
                                         @ApiParam(value = "站点ID") Integer stationId,
                                         @ApiParam(value = "接口版本") Integer version) {
        logger.info("/getSessionKeyAndOpenID");
        logger.info("微信小程序获取用户openId和sessionKey入参code和enterpriseId: " + code + "-----" + enterpriseId);
        Gson gson = new Gson();
        //返回结果集

        ResultData resultData = null;
        // 新版本
        if (version != null && version >= 1) {
            String appId = "";          //微信小程序appID
            String appSecret = "";      //微信小程序密钥
            Integer currentEnterpriseId = null;
            // 通过站点id拿到油企id
            if (enterpriseId == null) {
                if (stationId == null) {
                    return gson.toJson(ResultData.error(CodeMsg.REQUEST_FAIL));
                }
                Station station = enterpriseService.selectStationById(stationId);
                if (station == null) {
                    resultData = ResultData.error(new CodeMsg(-1, "站点参数不对"));
                    return gson.toJson(resultData);
                }
                // 拿到油企id
                currentEnterpriseId = station.getEnterpriseId();
            } else {
                currentEnterpriseId = enterpriseId;
            }

            Enterprise enterprise = enterpriseService.selectEnterpriseInfo(currentEnterpriseId);

            appId = enterprise.getAppId();
            appSecret = enterprise.getAppSecret();
            if (StringUtils.isNotBlank(appId) && StringUtils.isNotBlank(appSecret)) {
                logger.info("油企信息：" + enterprise.toString());
                Map<String, Object> userSessionKeyAndOpenID = WeiXinUserUtil.getUserSessionKeyAndOpenID(appId, appSecret, code);
                resultData = ResultData.success(userSessionKeyAndOpenID);
            } else {
                resultData = ResultData.error(new CodeMsg(-1, "配置信息不全"));
            }
            return gson.toJson(resultData);
        }

        // 老版本
        if (enterpriseId != null && StringUtils.isNotBlank(code)) {
            String appId = "";          //微信小程序appID
            String appSecret = "";      //微信小程序密钥
            Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
            appId = enterprise.getAppId();
            appSecret = enterprise.getAppSecret();
            if (enterprise != null && StringUtils.isNotBlank(enterprise.getAppId()) && StringUtils.isNotBlank(enterprise.getAppSecret())) {
                logger.info("油企信息：" + enterprise.toString());
                Map<String, Object> userSessionKeyAndOpenID = WeiXinUserUtil.getUserSessionKeyAndOpenID(appId, appSecret, code);
                resultData = ResultData.success(userSessionKeyAndOpenID);
            } else {
                resultData = ResultData.error(CodeMsg.STATION_NULL_INFO);
            }
        } else {
            resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
        }
        return gson.toJson(resultData);
    }

    /***
     * 登录入口
     * @param code
     * @return
     */
    @ResponseBody
    @GetMapping(value = "/loginGetPhone")
    @ApiOperation(value = "根据code，获取手机号", httpMethod = "GET", notes = "微信小程序根据code获取用户openId和sessionKey")
    @Transactional
    public String getPhoneWithLogin(
            @ApiParam(value = "code码", required = true) @RequestParam String code,
            @ApiParam(value = "站点ID") Integer stationId,
            @ApiParam(value = "解密码", required = true) @RequestParam String encryptedData,
            @ApiParam(value = "偏移量", required = true) @RequestParam String iv,
            @ApiParam(value = "昵称") String blogNickName,
            @ApiParam(value = "性别") String sexFlag,
            @ApiParam(value = "头像") String blogProfilePhoto,
            @ApiParam(value = "接口版本") Integer version
    ) {

        logger.info("/loginGetPhone-" + code + "--stationId:" + stationId);
        String key = IdempotentUtil.GenerateKey("loginGetPhone", code, iv);
        if (!idempotentUtil.tryLock(key)) {
            logger.error("/loginGetPhone接口频繁请求，time:{}", System.currentTimeMillis());
            return ResultData.errorJson("request frequently");
        }
        try {
//            if(version != 1){
//                throw new EndingException("该接口版本为1");
//            }

            String openId = null;
            String phoneNumber = null;


            Station station = enterpriseService.selectStationById(stationId);
            if (station == null) {
                throw new EndingException("未查到油站");
            }
            Integer enterpriseId = station.getEnterpriseId();


            Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
            String appId = enterprise.getAppId();
            String appSecret = enterprise.getAppSecret();

            if (StringUtils.isBlank(appId) || StringUtils.isBlank(appSecret)) {
                throw new EndingException("油企配置不全(appSecret,appId)");
            }

            Map<String, Object> sessionKeyAndOpenID = WeiXinUserUtil.getUserSessionKeyAndOpenID(appId, appSecret, code);

            String sessionKey = (String) sessionKeyAndOpenID.get("sessionKey");
            openId = (String) sessionKeyAndOpenID.get("openId");

            if (StringUtils.isBlank(sessionKey) || StringUtils.isBlank(openId)) {
                throw new EndingException("查询sessionKeyAndOpenID失败");
            }

            net.sf.json.JSONObject phoneJson = AesDecryptUtil.decryptEncryptedData(encryptedData, sessionKey, iv, "UTF-8");

            phoneNumber = (String) phoneJson.get("phoneNumber");

            if (StringUtils.isBlank(phoneNumber)) {
                throw new EndingException("解密手机号失败");
            }


            insertUserInfo(AppUserInfoRequest.builder()
                    .appType("1")
                    .openId(openId)
                    .blogNickName(blogNickName)
                    .sexFlag(sexFlag)
                    .blogProfilePhoto(blogProfilePhoto)
                    .mobilePhone(phoneNumber)
                    .enterpriseId(enterpriseId)
                    .stationId(stationId)
                    .build());

            Map<String, Object> result = new HashMap<>();
            result.put("openId", openId);
            result.put("phoneNumber", phoneNumber);


            return ResultData.successJson(result);


        } catch (EndingException e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultData.errorJsonWithCode(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("/insertUserInfo-", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultData.errorJson(e.getMessage());
        } finally {
            idempotentUtil.releaseLock(key);
        }
    }

    @PostMapping("/increaseShareCount")
    @ApiOperation(value = "增加分享次数", notes = "根据用户ID增加分享次数")
    @ResponseBody
    public void increaseShareCount(@RequestParam("userId") Long userId) {
        try {
            appUserInfoService.increaseShareCount(userId);
        } catch (Exception e) {
            e.printStackTrace();
            // Handle the exception as needed
        }
    }

    @GetMapping("/getShareCount")
    @ApiOperation(value = "获取分享次数", notes = "根据用户ID获取分享次数")
    @ResponseBody
    public Integer getShareCountByUserId(@RequestParam("userId") Long userId) {
        try {
            Integer count = appUserInfoService.getShareCountByUserId(userId);
            return count;
        } catch (Exception e) {
            e.printStackTrace();
            // Handle the exception as needed
            return null; // Return an appropriate value or throw a custom exception
        }
    }

    public void insertUserInfo(AppUserInfoRequest appUserInfoRequest) throws EndingException {
        logger.info("/insertUserInfo---" +
                "mobilePhone：" + appUserInfoRequest.getMobilePhone() +
                "；appType：" + appUserInfoRequest.getAppType() +
                "; enterpriseId:" + appUserInfoRequest.getEnterpriseId() +
                "; stationId:" + appUserInfoRequest.getStationId() +
                "; openId:" + appUserInfoRequest.getOpenId() +
                "; aliUserid:" + appUserInfoRequest.getAliUserId()
        );
        String appType = appUserInfoRequest.getAppType();

        if (StringUtils.isBlank(appType)) {
            throw new EndingException("用户来源类型appType不能为空");
        }

        if (appType == null) {
            throw new EndingException("缺少appType参数");
        }


        if ("1".equals(appType) && appUserInfoRequest.getOpenId() == null) {
            throw new EndingException("缺少openId参数");
        }

        if ("2".equals(appType) && appUserInfoRequest.getAliUserId() == null) {
            throw new EndingException("缺少aliUserId参数");
        }

        // 处理用户资料 归档站点 消除重复
        Integer enterpriseId = null;
        AppUserInfo appUserInfoExist = null;

        switch (appType) {
            case "1":       //当为微信用户时
                enterpriseId = appUserInfoRequest.getEnterpriseId();

                // 规整账号信息
                AppUserInfo wxIdTmp = appUserInfoService.getAppUserInfo(AppUserInfo.builder().stationId(enterpriseId).minaOpenid(appUserInfoRequest.getOpenId()).build());
                AppUserInfo wxPhoneTmp = appUserInfoService.getAppUserInfo(AppUserInfo.builder().stationId(enterpriseId).mobilePhone(appUserInfoRequest.getMobilePhone()).build());
                if (wxIdTmp != null) {
                    if (wxPhoneTmp != null && (!wxIdTmp.getUserId().equals(wxPhoneTmp.getUserId()))) {

                        // 此逻辑处理 1  mini正确  phone 错
                        //          2 blog  正确   phone 正确
                        //          3 mini 正确    phone 正确 情况

                        logger.info("/insertUserInfo-" + appUserInfoRequest.getMobilePhone() + "--进入微信特殊处理情况");

                        // 处理导入的情况，积分转换 清除多余的数据
                        if (handleDeleteUserInfo(wxIdTmp, wxPhoneTmp))
                            throw new EndingException("操作失败");
                    }
                    appUserInfoExist = wxIdTmp;
                } else {
                    if (wxPhoneTmp != null) {
                        appUserInfoExist = wxPhoneTmp;
                    }
                }

                break;
            case "2":
                Station station = enterpriseService.selectStationById(appUserInfoRequest.getStationId());
                enterpriseId = station.getEnterpriseId();

                // 规整账号信息
                AppUserInfo aliIdTmp = appUserInfoService.getAppUserInfo(AppUserInfo.builder().stationId(enterpriseId).aliUserId(appUserInfoRequest.getAliUserId()).build());
                AppUserInfo aliPhoneTmp = appUserInfoService.getAppUserInfo(AppUserInfo.builder().stationId(enterpriseId).mobilePhone(appUserInfoRequest.getMobilePhone()).build());

                if (aliIdTmp != null) {
                    if (aliPhoneTmp != null && (!aliIdTmp.getUserId().equals(aliPhoneTmp.getUserId()))) {
                        // 此逻辑处理 1 ali 正确  phone 错
                        //          2 blog  正确   phone 正确
                        //          3 ali 正确    phone 正确 情况
                        logger.info("/insertUserInfo-" + appUserInfoRequest.getMobilePhone() + "--进入支付宝特殊处理情况");

                        // 处理导入的情况，积分转换 清除多余的数据
                        if (handleDeleteUserInfo(aliIdTmp, aliPhoneTmp))
                            throw new EndingException("操作失败");
                    }
                    appUserInfoExist = aliIdTmp;
                } else {
                    if (aliPhoneTmp != null) {
                        appUserInfoExist = aliPhoneTmp;
                    }
                }
                break;
        }

        if (appUserInfoExist != null) {
            //更新
            if (appUserInfoExist.getUserId() == null) {
                throw new EndingException("操作失败");
            }
            appUserInfoService.updateAppUserInfoByUserId(AppUserInfo.builder()
                    .userId(appUserInfoExist.getUserId())
                    .integral(appUserInfoExist.getIntegral())
                    .stationId(enterpriseId)
                    .sex(appUserInfoRequest.getSexFlag())
                    .minaOpenid(appUserInfoRequest.getOpenId())
                    .blogNickName(appUserInfoRequest.getBlogNickName())
                    .blogProfilePhoto(appUserInfoRequest.getBlogProfilePhoto())
                    .updateDate(new Date())
                    .aliUserId(appUserInfoRequest.getAliUserId())
                    .mobilePhone(appUserInfoRequest.getMobilePhone())
                    .build());
            logger.info("/insertUserInfo-" + appUserInfoRequest.getMobilePhone() + "-- userUpdate");
        } else {
            //新增
            appUserInfoService.addAppUserInfo(AppUserInfo.builder()
                    .stationId(enterpriseId)
                    .sex(appUserInfoRequest.getSexFlag())
                    .blogNickName(appUserInfoRequest.getBlogNickName())
                    .blogProfilePhoto(appUserInfoRequest.getBlogProfilePhoto())
                    .registeDate(new Date())
//                    .memberCode(new SimpleDateFormat("yyMMdd").format(new Date())+ RandomStringUtils.randomNumeric(5))
                    .minaOpenid(appUserInfoRequest.getOpenId())
                    .aliUserId(appUserInfoRequest.getAliUserId())
                    .mobilePhone(appUserInfoRequest.getMobilePhone())
                    .integral(0)
                    .growUpValue(0)
                    .build());
            logger.info("/insertUserInfo-" + appUserInfoRequest.getMobilePhone() + "-- userAdd");
        }


    }

    @ResponseBody
    @RequestMapping(value = "/getSessionKeyAndOpenIDByAppType")
    public String getSessionKeyAndOpenIDByAppType(@RequestParam String code, Integer appType) {
        logger.info("微信小程序获取用户openId和sessionKey入参code和appType: " + code + "-----" + appType);
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        if (appType != null && StringUtils.isNotBlank(code)) {
            String appId = "";        //微信小程序appID
            String appSecret = "";      //微信小程序密钥
            switch (appType.toString()) {
                case "1":
                    //易核销小程序：
                    //AppID(小程序ID)wx646259775ca8425b
                    //密钥：7f5add461319eb61dcc23ebbb412af3f
                    appId = "wx646259775ca8425b";
                    appSecret = "7f5add461319eb61dcc23ebbb412af3f";
                    break;
                case "2":
                    //易加助手小程序：
                    //AppID(小程序ID)wx2369839a697f1614
                    //密钥：2745c645e7456cf56d901b2d42000f31
                    appId = "wx2369839a697f1614";
                    appSecret = "2745c645e7456cf56d901b2d42000f31";
                    break;
            }
            Map<String, Object> userSessionKeyAndOpenID = WeiXinUserUtil.getUserSessionKeyAndOpenID(appId, appSecret, code);
            resultData = ResultData.success(userSessionKeyAndOpenID);
        } else {
            resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
        }
        return gson.toJson(resultData);
    }


    @ResponseBody
    @RequestMapping(value = "/getPaySessionKeyAndOpenID")
    public String getPaySessionKeyAndOpenID(@RequestParam String code, @ApiParam(value = "油企ID") @RequestParam Integer enterpriseId) {
        logger.info("微信小程序获取用户openId和sessionKey入参code和appType: " + code + "|enterpriseId:" + enterpriseId);
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
        if (enterprise == null) {
            logger.info("未查到油站|enterpriseId:" + enterpriseId);
            return gson.toJson("未查到油站");
        }
        if (StringUtils.isBlank(enterprise.getAppId()) || StringUtils.isBlank(enterprise.getAppSecret())) {
            logger.info("油站配置不全|enterpriseId:" + enterpriseId);
            return gson.toJson("油站配置不全");
        }
        String appId = enterprise.getAppId();
        String appSecret = enterprise.getAppSecret();
//        String appId = "";        //微信小程序appID
//        String appSecret = "";      //微信小程序密钥
//        appId = "wx3d56fc8b214444d2";
//        appSecret = "f822422940490b23e7d5f3f39942ad07";
        Map<String, Object> userSessionKeyAndOpenID = WeiXinUserUtil.getUserSessionKeyAndOpenID(appId, appSecret, code);
        resultData = ResultData.success(userSessionKeyAndOpenID);
        return gson.toJson(resultData);
    }

    /*
     * 解密 encryptedData
     * @param sessionKey
     * @param encryptedData
     * @param iv
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/decryptEncryptedData", method = RequestMethod.POST, consumes = "application/json")
    @ApiOperation(value = "解密获取手机号", httpMethod = "POST", notes = "解密获取手机号")
    public String decryptEncryptedData(@RequestBody JSONObject jsonObject) {
        logger.info("解密获取手机号前台传入参数：" + jsonObject.toString());
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        String encryptedData = jsonObject.get("encryptedData").toString();
        String sessionKey = jsonObject.get("sessionKey").toString();
        String iv = jsonObject.get("iv").toString();
        if (StringUtils.isNotBlank(encryptedData) && StringUtils.isNotBlank(sessionKey) && StringUtils.isNotBlank(iv)) {
            net.sf.json.JSONObject jsonObject1 = AesDecryptUtil.decryptEncryptedData(encryptedData, sessionKey, iv, "UTF-8");
            resultData = ResultData.success(jsonObject1);
        } else {
            resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
        }
        return gson.toJson(resultData);
    }

    /*
     * JS-SDK使用权限签名算法
     * @param noncestr  随机字符串
     * @param timestamp 时间戳
     * @param url   页面访问路径
     * @param stationId 油站ID
     * @return
     */
    @RequestMapping(value = "/getSignature", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "JS-SDK使用权限签名算法", httpMethod = "GET", notes = "JS-SDK使用权限签名算法")
    public String getSignature(@ApiParam(value = "随机字符串", required = true) @RequestParam String noncestr,
                               @ApiParam(value = "时间戳", required = true) @RequestParam String timestamp,
                               @ApiParam(value = "页面访问路径", required = true) @RequestParam String url,
                               @ApiParam(value = "油企ID", required = true) @RequestParam Integer enterpriseId) {
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        logger.info("JS-SDK使用权限签名算法前台传来参数: " + "油企ID：" + enterpriseId + "; noncestr: " + noncestr + "; timestamp: " + timestamp + "; url: " + url);
        Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
        String gzhAppId = "";
        String gzhAppSecret = "";
        String accessToken = "";
        if (enterprise != null && StringUtils.isNotBlank(enterprise.getGzhAppId()) && StringUtils.isNotBlank(enterprise.getGzhAppSecret())) {
            gzhAppId = enterprise.getGzhAppId();
            gzhAppSecret = enterprise.getGzhAppSecret();
            accessToken = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
            //当前用户登录的公众号redis缓存中的jsapi_ticket
            String appIdTicket = "jsapi_ticket_" + gzhAppId;
            String jsapiTicket = "";
            if (redisCacheUtil.hasKey(appIdTicket)) {
                jsapiTicket = redisCacheUtil.getCacheObject(appIdTicket);
            } else {
                //获取jsapi_ticket
                net.sf.json.JSONObject gzhJsapiTicket = WeiXinUserUtil.getGzhJsapiTicket(accessToken);
                if (gzhJsapiTicket.containsKey("ticket")) {
                    redisCacheUtil.setCacheObject(appIdTicket, gzhJsapiTicket.get("ticket"));
                    redisCacheUtil.expire(appIdTicket, 7100, TimeUnit.SECONDS);
                    jsapiTicket = gzhJsapiTicket.get("ticket").toString();
                }
            }
            String string1 = "jsapi_ticket=" + jsapiTicket + "&noncestr=" + noncestr + "&timestamp=" + timestamp + "&url=" + url;
            logger.info("签名参数拼接：" + string1);
            //sha1加密
            String signature = DigestUtils.sha1Hex(string1);
            logger.info("JS-SDK签名参数sha1加密后：" + signature);
            resultData = ResultData.success(signature);
        }
        return gson.toJson(resultData);
    }

    /*
     * 微信卡券签名
     * @param noncestr
     * @param timestamp
     * @param enterpriseId
     * @return
     */
    @RequestMapping(value = "/getCardSignature", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "微信卡券签名", httpMethod = "GET", notes = "微信卡券签名")
    public String getCardSignature(@ApiParam(value = "随机字符串", required = true) @RequestParam String noncestr,
                                   @ApiParam(value = "时间戳", required = true) @RequestParam String timestamp,
                                   @ApiParam(value = "卡券ID", required = true) @RequestParam String cardId,
                                   @ApiParam(value = "油企ID", required = true) @RequestParam Integer enterpriseId) {
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        logger.info("微信卡券前台传来参数: " + "油企ID：" + enterpriseId + "; noncestr: " + noncestr + "; timestamp: " + timestamp + ";");
        Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
        String gzhAppId = "";
        String gzhAppSecret = "";
        String accessToken = "";
        if (enterprise != null && StringUtils.isNotBlank(enterprise.getGzhAppId()) && StringUtils.isNotBlank(enterprise.getGzhAppSecret())) {
            gzhAppId = enterprise.getGzhAppId();
            gzhAppSecret = enterprise.getGzhAppSecret();
            accessToken = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
            //logger.info("微信卡券所需accessToken：" + accessToken);
            //当前用户登录的公众号redis缓存中的卡券api_ticket
            String appIdCardTicket = "card_api_ticket_" + gzhAppId;
            String cardApiTicket = "";
            if (redisCacheUtil.hasKey(appIdCardTicket)) {
                cardApiTicket = redisCacheUtil.getCacheObject(appIdCardTicket);
            } else {
                //获取jsapi_ticket
                net.sf.json.JSONObject gzhCardApiTicket = WeiXinUserUtil.getGzhCardApiTicket(accessToken);
                if (gzhCardApiTicket.containsKey("ticket")) {
                    redisCacheUtil.setCacheObject(appIdCardTicket, gzhCardApiTicket.get("ticket"));
                    redisCacheUtil.expire(appIdCardTicket, 7100, TimeUnit.SECONDS);
                    cardApiTicket = gzhCardApiTicket.get("ticket").toString();
                }
            }
            logger.info("微信卡券api-ticket: " + cardApiTicket);
            //String cardId = "pJR5R6qK9hZTOBUp0VJvY9R2pCLo"; //微信卡券ID
            //pJR5R6gq42sGUo8EEYeWZzIFoeyY
            //String cardId = "pJR5R6gq42sGUo8EEYeWZzIFoeyY"; //微信卡券ID
            //海底捞 pJR5R6qNNdJR3s_yCtjAj6BbYcP8
            //String cardId = "pJR5R6qNNdJR3s_yCtjAj6BbYcP8"; //微信卡券ID

            //排序参数，SHA1加密；
            List<String> strList = new ArrayList<>();
            Collections.addAll(strList, timestamp, noncestr, cardApiTicket, cardId);
            Collections.sort(strList);
            String strs = "";
            for (String s : strList) strs += s;
            logger.info("排序后拼接的字符串:" + strs);
            String signature = DigestUtils.sha1Hex(strs);
            logger.info("微信卡券签名参数sha1加密后：" + signature);
            Map<String, Object> result = new HashMap<>();
            result.put("cardApiTicket", cardApiTicket);
            result.put("signature", signature);
            result.put("cardId", cardId);
            result.put("accessToken", accessToken);
            resultData = ResultData.success(result);
        } else {
            resultData = ResultData.error(CodeMsg.ENTERPRISE_NULL_INFO);
        }
        return gson.toJson(resultData);
    }

    /*
     * 判断使用小程序支付的用户是否关注公众号
     * @param unionId
     * @param stationId
     * @return
     */
    @RequestMapping(value = "/whetherFollowGzh", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "判断使用小程序支付的用户是否关注公众号", httpMethod = "GET", notes = "判断使用小程序支付的用户是否关注公众号")
    public String whetherFollowGzh(@ApiParam(value = "用户unionId", required = true) @RequestParam String unionId,
                                   @ApiParam(value = "油企ID", required = true) @RequestParam Integer enterpriseId) {
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        if (unionId != null) {
            Map<String, String> param = new HashMap<>();
            param.put("unionId", unionId);
            param.put("userType", "1");
            param.put("stationId", enterpriseId.toString());
            String openId = appUserInfoService.whetherFollowGzh(param);
            if (openId != null) {
                Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
                String gzhAppId = "";
                String gzhAppSecret = "";
                String accessToken = "";
                if (enterprise != null && StringUtils.isNotBlank(enterprise.getGzhAppId()) && StringUtils.isNotBlank(enterprise.getGzhAppSecret())) {
                    gzhAppId = enterprise.getGzhAppId();
                    gzhAppSecret = enterprise.getGzhAppSecret();
                    accessToken = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
                    net.sf.json.JSONObject unionIdInfo = WeiXinUserUtil.getUnionIdInfo(accessToken, openId);
                    logger.info("用户公众号信息：" + unionIdInfo);
                    if (unionIdInfo.containsKey("subscribe") && unionIdInfo.get("subscribe").equals(1)) {
                        resultData = ResultData.success(CodeMsg.SUCCESS);
                    } else {
                        resultData = ResultData.error(CodeMsg.NO_FollowGzh);
                    }
                } else {
                    resultData = ResultData.error(CodeMsg.SEARCH_APPID_FAIL);
                }
            } else {
                resultData = ResultData.error(CodeMsg.USERGZHINFO_EXSIST);
            }
        }
        return gson.toJson(resultData);
    }

    /*
     * 获取公众号授权后的信息
     * @param code
     * @param stationId
     * @return
     */
    @RequestMapping(value = "/getGzhAuthorizeInfo", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取公众号授权后的信息", httpMethod = "GET", notes = "获取公众号授权后的信息")
    public String getGzhAuthorizeInfo(@ApiParam(value = "code码", required = true) @RequestParam String code,
                                      @ApiParam(value = "油企ID", required = true) @RequestParam Integer enterpriseId) {
        logger.info("获取公众号授权后的信息前端传递参数：code：[{}],enterpriseId：[{}]", code, enterpriseId);
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
        if (code != null && enterpriseId != null) {
            String gzhAppId = "";
            String gzhAppSecret = "";
            String redisKey = RedisKey.WX_CODE_KEY + enterpriseId + code;
            String cacheRes = redisCacheUtil.getCacheObject(redisKey);
            if (cacheRes != null) {
                logger.info("redis有缓存,cache:[{}]", cacheRes);
                Map map = null;
                try {
                    map = JsonUtils.jsonToObject(cacheRes, Map.class);
                } catch (IOException e) {
                    logger.error(e.getMessage(), e);
                }
                resultData = ResultData.success(map);
            } else {
                if (enterprise != null && StringUtils.isNotBlank(enterprise.getGzhAppId()) && StringUtils.isNotBlank(enterprise.getGzhAppSecret())) {
                    gzhAppId = enterprise.getGzhAppId();
                    gzhAppSecret = enterprise.getGzhAppSecret();
                    net.sf.json.JSONObject gzhAuthorizeInfo = WeiXinUserUtil.getGzhAuthorizeInfo(gzhAppId, gzhAppSecret, code);
                    logger.info("非第三方授权获取到信息：{}", gzhAuthorizeInfo);
                    redisCacheUtil.setCacheObject(redisKey, gzhAuthorizeInfo.toString(), 12, TimeUnit.HOURS);
                    resultData = ResultData.success(gzhAuthorizeInfo);
                } else if (enterprise != null && StringUtils.isNotBlank(enterprise.getGzhAppId())) {
                    net.sf.json.JSONObject jsonObject = WeiXinUserUtil.getUserAccessToken(enterprise.getGzhAppId(), componentAppid, code);
                    logger.info("第三方授权获取到信息：{}", jsonObject);
                    redisCacheUtil.setCacheObject(redisKey, jsonObject.toString(), 12, TimeUnit.HOURS);
                    resultData = ResultData.success(jsonObject);
                } else {
                    resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
                }
            }
        } else {
            resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
        }
        return gson.toJson(resultData);
    }

    //获取油站公众号ID
    @RequestMapping(value = "/getStat", method = RequestMethod.GET)
    @ResponseBody
    public String getStationGzh(@RequestParam Integer enterpriseId) {
        net.sf.json.JSONObject jsonObject = WeiXinUserUtil.getUserAccessToken("11", componentAppid, "22");
        return "111";
    }

    //获取油站公众号ID
    @RequestMapping(value = "/getStationGzhAppId", method = RequestMethod.GET)
    @ResponseBody
    public String getStationGzhAppId(@RequestParam Integer enterpriseId) {
        logger.info("开始查询该油站公众号enterpriseId=" + enterpriseId);
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        if (enterpriseId != null) {
            Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
            if (enterprise != null && StringUtils.isNotBlank(enterprise.getGzhAppId())) {
                String gzhAppId = enterprise.getGzhAppId();
                Map<String, Object> map = new HashMap<>();
                map.put("appId", gzhAppId);
                logger.info("该油站公众号：" + gzhAppId);
                resultData = ResultData.success(map);
                logger.info("油站公众号resultData=" + gson.toJson(resultData));
            } else {
                logger.info("油站或者GzhAppId为null，油站公众号enterpriseId=" + enterpriseId);
                resultData = ResultData.error(CodeMsg.SEARCH_APPID_FAIL);
            }
        } else {
            logger.info("enterpriseId为null");
            resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
        }
        return gson.toJson(resultData);
    }


    /*
     * 获取公众号信息
     * @param openId
     * @param stationId
     * @return
     */
    @RequestMapping(value = "/getGzhUserInfo", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取公众号用户信息", httpMethod = "GET", notes = "获取公众号用户信息")
    public String getGzhUserInfo(@ApiParam(value = "公众号openId", required = true) @RequestParam String openId,
                                 @ApiParam(value = "油企ID", required = true) @RequestParam Integer enterpriseId) {
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        if (openId != null && enterpriseId != null) {
            String gzhAppId = "";
            String gzhAppSecret = "";
            String accessToken = "";
            Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
            if (enterprise != null && StringUtils.isNotBlank(enterprise.getGzhAppId()) && StringUtils.isNotBlank(enterprise.getGzhAppSecret())) {
                gzhAppId = enterprise.getGzhAppId();
                gzhAppSecret = enterprise.getGzhAppSecret();
                accessToken = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
                net.sf.json.JSONObject unionIdInfo = null;
                unionIdInfo = WeiXinUserUtil.getUnionIdInfo(accessToken, openId);
                if (unionIdInfo.containsKey("errcode")) {
                    String accessTokenKey = "access_token_" + gzhAppId;
                    //删除原来key
                    redisCacheUtil.deleteObject(accessTokenKey);
                    String token = WeiXinUserUtil.getToken(gzhAppId, gzhAppSecret).getAccessToken();
                    redisCacheUtil.setCacheObject(accessTokenKey, token);
                    redisCacheUtil.expire(accessTokenKey, 7100, TimeUnit.SECONDS);
                    unionIdInfo = WeiXinUserUtil.getUnionIdInfo(token, openId);
                }
                resultData = ResultData.success(unionIdInfo);
            }
        } else {
            resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
        }
        return gson.toJson(resultData);
    }

    @GetMapping("/getToken")
    @ResponseBody
    public String getAccessToken(String appId, String appSecret) {
        return new Gson().toJson(this.getTokenByRedisCache(appId, appSecret));
    }


    /*
     * 从Redis缓存中获取 tokenCache
     * @param appId
     * @param appSecret
     * @return
     */
    public synchronized String getTokenByRedisCache(String appId, String appSecret) {
        logger.info("appId参数: " + appId + " ;appSecret参数: " + appSecret);
        //redis缓存key
        String accessTokenKey = "access_token_" + appId;
        if (!redisCacheUtil.hasKey(accessTokenKey) || redisCacheUtil.getCacheObject(accessTokenKey) == null || redisCacheUtil.getCacheObject(accessTokenKey).equals("")) {
////            String token = WeiXinUserUtil.getToken(appId, appSecret).getAccessToken();
//            net.sf.json.JSONObject jsonObject= HttpRequestUtil.getHttpsRequestData("","post","");
//            String token = jsonObject.getString("");

//            String token =HttpRequestUtil.getAcccessTokenHttpsRequestData(tokenHttp,"get","\""+appId+"\"");

            String token = "";
            if (Objects.isNull(appSecret)) {
                RestTemplate restTemplate = new RestTemplate();
                token = restTemplate.getForObject(adminName + "/prod-api/thirdParty/weChat/getAccessToken?authorizerAppid=" + appId, String.class);
            } else {
                token = WeiXinUserUtil.getToken(appId, appSecret).getAccessToken();
            }
            redisCacheUtil.setCacheObject(accessTokenKey, token);
            redisCacheUtil.expire(accessTokenKey, 7100, TimeUnit.SECONDS);
            logger.info("设置Redis缓存中" + appId + "的token信息: " + token);
            return token;
        } else {
            String cacheToken = redisCacheUtil.getCacheObject(accessTokenKey);
            logger.info("Redis缓存中" + appId + "的token信息: " + cacheToken);
            return cacheToken;
        }

    }

    /*
     * 添加用户信息
     * @param request
     * @return
     */
    @RequestMapping(value = "/addAppUserInfo", method = RequestMethod.POST)
    @ResponseBody
    @Transactional
    public String addAppUserInfo(@RequestBody AppUserInfoRequest request) {
        logger.info("/addAppUserInfo---" +
                "mobilePhone：" + request.getMobilePhone() +
                "；appType：" + request.getAppType() +
                "; enterpriseId:" + request.getEnterpriseId() +
                "; stationId:" + request.getStationId() +
                "; openId:" + request.getOpenId() +
                "; aliUserid:" + request.getAliUserId()
        );
        Gson gson = new Gson();
        String appType = request.getAppType();
        if (StringUtils.isNotBlank(appType)) {
            String key = IdempotentUtil.GenerateKey("addAppUserInfo", request.getMobilePhone(), request.getAppType(), request.getOpenId(), request.getAliUserId());
            if (!idempotentUtil.tryLock(key)) {
                logger.error("/addAppUserInfo接口频繁请求，time:{}", System.currentTimeMillis());
                return ResultData.errorJson("request frequently");
            }
//            if("1".equals(appType) && null == request.getEnterpriseId())
//                return new Gson().toJson(ResultData.error(CodeMsg.PARAMS_NUll, "微信用户新增时，油企ID不能为空"));
//            if("2".equals(appType) && null == request.getStationId())
//                return new Gson().toJson(ResultData.error(CodeMsg.PARAMS_NUll, "支付宝用户新增时，油站ID不能为空"));
            if (appType == null) {
                return new Gson().toJson(ResultData.error(new CodeMsg(-1, "缺少appType参数")));
            }

            if ("1".equals(appType) && request.getOpenId() == null) {
                return new Gson().toJson(ResultData.error(new CodeMsg(-1, "缺少openId参数")));
            }

            if ("2".equals(appType) && request.getAliUserId() == null) {
                return new Gson().toJson(ResultData.error(new CodeMsg(-1, "缺少aliUserId参数")));
            }

            // 处理用户资料 归档站点 消除重复
            Integer enterpriseId = null;
            AppUserInfo appUserInfoExist = null;

            switch (appType) {
                case "1":       //当为微信用户时
                    Integer stationId = request.getStationId();
                    if (stationId == null) {
                        enterpriseId = request.getEnterpriseId();
                    } else {
                        Station station = enterpriseService.selectStationById(stationId);
                        enterpriseId = station.getEnterpriseId();
                    }

                    // 规整账号信息
                    AppUserInfo wxIdTmp = appUserInfoService.getAppUserInfo(AppUserInfo.builder().stationId(enterpriseId).minaOpenid(request.getOpenId()).build());
                    AppUserInfo wxPhoneTmp = appUserInfoService.getAppUserInfo(AppUserInfo.builder().stationId(enterpriseId).mobilePhone(request.getMobilePhone()).build());
                    if (wxIdTmp != null) {
                        if (wxPhoneTmp != null && (!wxIdTmp.getUserId().equals(wxPhoneTmp.getUserId()))) {

                            // 此逻辑处理 1  mini正确  phone 错
                            //          2 blog  正确   phone 正确
                            //          3 mini 正确    phone 正确 情况

                            logger.info("/addAppUserInfo-" + request.getMobilePhone() + "--进入微信特殊处理情况");

                            // 处理导入的情况，积分转换 清除多余的数据
                            if (handleDeleteUserInfo(wxIdTmp, wxPhoneTmp))
                                return new Gson().toJson(ResultData.error(new CodeMsg(-1, "操作失败")));
                        }
                        appUserInfoExist = wxIdTmp;
                    } else {
                        if (wxPhoneTmp != null) {
                            appUserInfoExist = wxPhoneTmp;
                        }
                    }

                    break;
                case "2":
                    Station station = enterpriseService.selectStationById(request.getStationId());
                    enterpriseId = station.getEnterpriseId();

                    // 规整账号信息
                    AppUserInfo aliIdTmp = appUserInfoService.getAppUserInfo(AppUserInfo.builder().stationId(enterpriseId).aliUserId(request.getAliUserId()).build());
                    AppUserInfo aliPhoneTmp = appUserInfoService.getAppUserInfo(AppUserInfo.builder().stationId(enterpriseId).mobilePhone(request.getMobilePhone()).build());

                    if (aliIdTmp != null) {
                        if (aliPhoneTmp != null && (!aliIdTmp.getUserId().equals(aliPhoneTmp.getUserId()))) {
                            // 此逻辑处理 1 ali 正确  phone 错
                            //          2 blog  正确   phone 正确
                            //          3 ali 正确    phone 正确 情况
                            logger.info("/addAppUserInfo-" + request.getMobilePhone() + "--进入支付宝特殊处理情况");

                            // 处理导入的情况，积分转换 清除多余的数据
                            if (handleDeleteUserInfo(aliIdTmp, aliPhoneTmp))
                                return new Gson().toJson(ResultData.error(new CodeMsg(-1, "操作失败")));
                        }
                        appUserInfoExist = aliIdTmp;
                    } else {
                        if (aliPhoneTmp != null) {
                            appUserInfoExist = aliPhoneTmp;
                        }
                    }
                    break;
            }

            if (appUserInfoExist != null) {
                //更新
                if (appUserInfoExist.getUserId() == null) {
                    return new Gson().toJson(ResultData.error(new CodeMsg(-1, "操作失败")));
                }
                AppUserInfo updateAppUserInfo = AppUserInfo.builder()
                        .userId(appUserInfoExist.getUserId())
                        .integral(appUserInfoExist.getIntegral())
                        .stationId(enterpriseId)
                        .sex(request.getSexFlag())
                        .minaOpenid(request.getOpenId())
                        .blogNickName(request.getBlogNickName())
                        .blogProfilePhoto(request.getBlogProfilePhoto())
                        .updateDate(new Date())
                        .aliUserId(request.getAliUserId())
                        .mobilePhone(request.getMobilePhone())
                        .build();
                if (updateAppUserInfo.getBlogOpenid() == null || updateAppUserInfo.getBlogOpenid().equals("")) {
                    List<String> a = null;
                    try {
                        a = appUserInfoService.checkUserCoupon(updateAppUserInfo);
                        if (a == null || a.size() == 0) {
                            updateAppUserInfo.setNumberOfEntry(1);
                            registrationReleaseService.registrationRelease(updateAppUserInfo);
                        }
                    } catch (Exception e) {
                        // 异常处理逻辑
                        e.printStackTrace(); // 这里只是简单打印异常信息，你可以根据实际需求进行处理
                    }
                }
                appUserInfoService.updateAppUserInfoByUserId(updateAppUserInfo);
                logger.info("/addAppUserInfo-" + request.getMobilePhone() + "-- userUpdate");
            } else {
                //新增
                AppUserInfo addAppUserInfo = AppUserInfo.builder()
                        .stationId(enterpriseId)
                        .sex(request.getSexFlag())
                        .blogNickName(request.getBlogNickName())
                        .blogProfilePhoto(request.getBlogProfilePhoto())
                        .registeDate(new Date())
//                        .memberCode(new SimpleDateFormat("yyMMdd").format(new Date())+ RandomStringUtils.randomNumeric(5))
                        .minaOpenid(request.getOpenId())
                        .aliUserId(request.getAliUserId())
                        .mobilePhone(request.getMobilePhone())
                        .integral(0)
                        .growUpValue(0)
                        .numberOfEntry(1)
                        .build();
                List<String> a = null;
                try {
                    a = appUserInfoService.checkUserCoupon(addAppUserInfo);
                    if (a == null || a.size() == 0) {
                        addAppUserInfo.setNumberOfEntry(1);
                        registrationReleaseService.registrationRelease(addAppUserInfo);
                    }
                } catch (Exception e) {
                    // 异常处理逻辑
                    e.printStackTrace(); // 这里只是简单打印异常信息，你可以根据实际需求进行处理
                }
                appUserInfoService.addAppUserInfo(addAppUserInfo);
                logger.info("/addAppUserInfo-" + request.getMobilePhone() + "-- userAdd");
                //注册发券
            }
            idempotentUtil.releaseLock(key);
            return gson.toJson(ResultData.success(CodeMsg.SUCCESS));
        } else {
            logger.info("/addAppUserInfo-" + request.getMobilePhone() + "-- appType is null");
            return gson.toJson(ResultData.error(CodeMsg.PARAMS_NUll, "用户来源类型appType不能为空"));
        }
    }

    private boolean handleDeleteUserInfo(AppUserInfo idTmp, AppUserInfo phoneTmp) {
        Integer idIntegral = idTmp.getIntegral() == null ? 0 : idTmp.getIntegral();
        Integer phoneIntegral = phoneTmp.getIntegral() == null ? 0 : phoneTmp.getIntegral();
        idTmp.setIntegral(idIntegral + phoneIntegral);

        if (phoneTmp.getUserId() == null) {
            return true;
        }
        phoneTmp.setIntegral(0);
        phoneTmp.setSetMobilePhoneIsNull(true);
        phoneTmp.setSetBlogOpenidIsNull(true);
        phoneTmp.setSetMinaOpenidIsNull(true);
        phoneTmp.setSetAliUserIdIsNull(true);
        phoneTmp.setUpdateDate(new Date());

        appUserInfoService.updateAppUserInfoByUserId(phoneTmp); // 选择清除1 留下2
        return false;
    }

    @ResponseBody
    @RequestMapping(value = "/getPaySessionKeyAndID")
    public String getPaySessionKeyAndID(@ApiParam(value = "油企ID") @RequestParam Integer enterpriseId) {
        logger.info("微信小程序获取appid 入参|enterpriseId:" + enterpriseId);
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
        if (enterprise == null) {
            logger.info("未查到油站|enterpriseId:" + enterpriseId);
            return gson.toJson("未查到油站");
        }
        if (StringUtils.isBlank(enterprise.getAppId()) || StringUtils.isBlank(enterprise.getAppSecret())) {
            logger.info("油站配置不全|enterpriseId:" + enterpriseId);
            return gson.toJson("油站配置不全");
        }
        String appId = enterprise.getAppId();
        String appSecret = enterprise.getAppSecret();
        Map<String, Object> userSessionKeyAndOpenID = new HashMap<>();
        userSessionKeyAndOpenID.put("appid", appId);
        userSessionKeyAndOpenID.put("appSecret", appSecret);
        resultData = ResultData.success(userSessionKeyAndOpenID);
        return gson.toJson(resultData);
    }

    @ResponseBody
    @GetMapping("/getOrCreateUserInfo")
    public ResultData<UserInfoVo> getOrCreateUserInfo(@RequestParam String openId,
                                                      @RequestParam String nickName,
                                                      @RequestParam Integer enterpriseId) {
        return ResultData.success(appUserInfoService.getOrCreateUserInfo(openId, nickName, enterpriseId));
    }


    @GetMapping("/inspectRegisteredUser")
    @ApiOperation(value = "检查用户是否注册成功")
    @ResponseBody
    public ResultData<AppUserInfo> inspectRegisteredUser(@ApiParam(value = "油企ID", required = true) @RequestParam Integer enterpriseId,
                                                         @ApiParam(value = "用户手机号", required = true) @RequestParam String mobilePhone) {

        AppUserInfo appUserInfo = AppUserInfo.builder().mobilePhone(mobilePhone).stationId(enterpriseId).build();
        AppUserInfo appUserInfoAndBalance = appUserInfoService.getAppUserInfo(appUserInfo);
        if (Objects.isNull(appUserInfoAndBalance)) {
            return ResultData.error(CodeMsg.USER_NOT_EXSIST);
        }


        Integer numberOfEntry = appUserInfoAndBalance.getNumberOfEntry();
        if (numberOfEntry == 1) {
            appUserInfoAndBalance.setNumberOfEntry(numberOfEntry + 1);
        } else if (numberOfEntry == 2 || numberOfEntry == 3) {
            appUserInfoAndBalance.setNumberOfEntry(numberOfEntry + 1);
        }

        appUserInfoService.updateAppUserInfo(appUserInfoAndBalance);
        logger.info("查询注册进入主页次数：手机号：{}，油企id：{}，进入次数：{}", appUserInfoAndBalance.getMobilePhone(), appUserInfoAndBalance.getStationId(), appUserInfoAndBalance.getNumberOfEntry());
        return ResultData.success(appUserInfoAndBalance);
    }

    /*
     * JS-SDK使用权限签名算法
     * @param noncestr  随机字符串
     * @param timestamp 时间戳
     * @param url   页面访问路径
     * @param stationId 油站ID
     * @return
     */
    @RequestMapping(value = "/getSignature2", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "JS-SDK使用权限签名算法", httpMethod = "GET", notes = "JS-SDK使用权限签名算法")
    public String getSignature2(@ApiParam(value = "随机字符串", required = true) @RequestParam String noncestr,
                                @ApiParam(value = "时间戳", required = true) @RequestParam String timestamp,
                                @ApiParam(value = "页面访问路径", required = true) @RequestParam String url,
                                @ApiParam(value = "油企ID", required = true) @RequestParam Integer enterpriseId) {
        Gson gson = new Gson();
        //返回结果集
        ResultData resultData = null;
        logger.info("JS-SDK使用权限签名算法前台传来参数: " + "油企ID：" + enterpriseId + "; noncestr: " + noncestr + "; timestamp: " + timestamp + "; url: " + url);
        Enterprise enterprise = enterpriseService.selectEnterpriseInfo(enterpriseId);
        String gzhAppId = "";
        String gzhAppSecret = "";
        String accessToken = "";
        if (enterprise != null && StringUtils.isNotBlank(enterprise.getGzhAppId())) {
            gzhAppId = enterprise.getGzhAppId();
            gzhAppSecret = enterprise.getGzhAppSecret();
            accessToken = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
            //当前用户登录的公众号redis缓存中的jsapi_ticket
            String appIdTicket = "jsapi_ticket_" + gzhAppId;
            String jsapiTicket = "";
            if (redisCacheUtil.hasKey(appIdTicket)) {
                jsapiTicket = redisCacheUtil.getCacheObject(appIdTicket);
            } else {
                //获取jsapi_ticket
                net.sf.json.JSONObject gzhJsapiTicket = WeiXinUserUtil.getGzhJsapiTicket(accessToken);
                if (gzhJsapiTicket.containsKey("ticket")) {
                    redisCacheUtil.setCacheObject(appIdTicket, gzhJsapiTicket.get("ticket"));
                    redisCacheUtil.expire(appIdTicket, 7100, TimeUnit.SECONDS);
                    jsapiTicket = gzhJsapiTicket.get("ticket").toString();
                }
            }
            String string1 = "jsapi_ticket=" + jsapiTicket + "&noncestr=" + noncestr + "&timestamp=" + timestamp + "&url=" + url;
            logger.info("签名参数拼接：" + string1);
            //sha1加密
            String signature = DigestUtils.sha1Hex(string1);
            logger.info("JS-SDK签名参数sha1加密后：" + signature);
            resultData = ResultData.success(signature);
        }
        return gson.toJson(resultData);
    }


}
